/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/maximum-subarray
   @Language: C++
   @Datetime: 19-06-20 10:59
   */

class Solution {
public:
	int maxSubArray(vector<int>& nums) {
		int mx=INT_MIN;
		for(int i=0, sum=0; i<nums.size(); ++i){
			sum+=nums[i];
			mx=max(mx,sum);
			if(sum<0) sum=0;
		}
		return mx;
	}
};
